#include <QPixmap>
#include "renamedialog.h"
#include "ui_renamedialog.h"



RenameDialog::RenameDialog(const QString & from, bool isFile, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::RenameDialog)
{
    ui->setupUi(this);
    ui->label_4->setPixmap( QPixmap(isFile? ":/icons/images/file.png" : ":/icons/images/folder.png").scaled(QSize(89, 89), Qt::KeepAspectRatio) );

    _from = from;

    int pos = from.lastIndexOf('/', isFile? -1 : 1);
    if(pos > -1)
    {
        ui->location_label->setText( from.mid(0, pos+1) );
        ui->current_name_lineEdit->setText( isFile? from.mid(pos+1) : from.mid(pos+1, from.length()-2) );
        ui->lineEdit->setText( isFile? from.mid(pos+1) : from.mid(pos+1, from.length()-2) );
    } else
        ui->lineEdit->setText( "Warning: File for rename has wrong name!");

    ui->lineEdit->setFocus();
}


RenameDialog::~RenameDialog()
{
    delete ui;
}


void RenameDialog::closeEvent(QCloseEvent *)
{
    deleteLater();
}


void RenameDialog::on_buttonBox_accepted()
{
    emit renamed(_from, ui->lineEdit->text());
    close();
}


void RenameDialog::on_buttonBox_rejected()
{
    close();
}
